package app.controllers.admin.game;

import app.models.DaoKit;
import app.models.game.SignRule;
import com.github.sog.controller.AjaxMessage;
import com.github.sog.controller.BasicController;
import com.github.sog.plugin.sqlinxml.SqlKit;

import java.util.Date;

/**
 * <p>
 * .
 * </p>
 *
 * @author Jerry Ou
 * @version 1.0 2014-02-12 13:41
 * @since JDK 1.6
 */
public class SignController extends BasicController {

    public void index() {
        SignRule signRule = SignRule.dao.findFirst(SqlKit.sql("signrule.list"));
        if (signRule == null) {
            signRule = new SignRule();
        }
        setAttr("signRule", signRule);
        render("index.ftl");
    }

    public void save() {
        SignRule signRule = getModel(SignRule.class, "signRule");
        if (DaoKit.isNew(signRule)) {
            signRule.set("create_time", new Date());
            signRule.set("update_time", new Date());
            signRule.save();
        } else {
            signRule.set("update_time", new Date());
            signRule.update();
        }
        renderJson(AjaxMessage.ok("保存成功"));
    }

}
